﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Wedo.Service.Common;
using Wedo.Recognition.Domain.Models;
using Wedo.Recognition.Domain;
using Wedo.Mvc.Pager;
using Wedo.Mvc.Utility;
using Wedo.Recognition.Domain;
using Wedo.Recognition.Repository;


namespace Wedo.Recognition.Service
{
    public class RecieveRecordService : BaseService<RecieveRecord> 
    {
        public RecieveRecordService(IUnitWork dbContext)
            : base(dbContext, dbContext.Set<RecieveRecord>())
        {

        }

        public PagedList<RecieveRecord> GetPagedList(CommonTimeSearch where)
        {
            where = where ?? new CommonTimeSearch();
            IQueryable<RecieveRecord> query=_repository.All();
            if (where.Keyword.IsNotNullOrWhiteSpace())
                query = query.Where(m => m.Assignment.Contains(where.Keyword));
            if (where.StartTime != null)
            {
                DateTime Start = where.StartTime.Value;
                query = query.Where(m => m.Created > Start);
            }
            if (where.EndTime != null)
            {
                DateTime endTime = where.EndTime.Value.AddDays(1);
                query = query.Where(m => m.Created < endTime);
            }
            return query.OrderByDescending(m => m.Created).ToPagedList(where.Page, 10);
        }
    }
}
